package com.dq.domain.message.custome;

import com.alibaba.fastjson.JSONObject;
import com.dq.vo.baseVo.VO;
import com.dq.domain.message.oneself.Message;
import com.dq.domain.record.ServiceRecord;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @author CF
 */
@Data
@Entity
@ApiModel("服务消息")
public class ServiceMessage extends Message {

    @ApiModelProperty("关联服务记录 实体对象")
    @ManyToOne
    public ServiceRecord serviceRecord;

    @ApiModelProperty("消息接受者，顾客")
    @ManyToOne
    public SysUser wxuser;


    @Data
    @ApiModel("视图")
    public static class Vo implements VO {
        protected Long id;

        @ApiModelProperty("未读/已读")
        public String messageStatusEn;
        @ApiModelProperty("未读/已读")
        public String messageStatusCn;
        @ApiModelProperty("消息类型")
        public String messageTypeEn;
        @ApiModelProperty("消息类型")
        public String messageTypeCn;

        @ApiModelProperty("关联 服务记录")
        public JSONObject serviceRecord;

        @ApiModelProperty("创建时间")
        public String createTime;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.id;

        vo.messageStatusEn = this.getMessageStatus().toString();
        vo.messageStatusCn = this.getMessageStatus().name;
        vo.messageTypeEn = this.getMessageType().toString();
        vo.messageTypeCn = this.getMessageType().name;

        vo.createTime = fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);

        // 服务记录 信息
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", this.serviceRecord.getId());
        jsonObject.put("serviceNo", this.serviceRecord.getServiceNo());
        // 技师信息
        jsonObject.put("staffUserId", this.serviceRecord.getStaffUser().getId());
        jsonObject.put("staffUserName", this.serviceRecord.getStaffUser().getUserRealcName());

        jsonObject.put("serviceBeginTime",fmt(this.serviceRecord.getServiceBeginTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS));
        jsonObject.put("serviceEndTime",fmt(this.serviceRecord.getServiceEndTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS));
        jsonObject.put("serviceBackAmount", this.serviceRecord.getServiceBackAmount());
        jsonObject.put("serviceStatusEn", this.serviceRecord.getServiceStatus().toString());
        jsonObject.put("serviceStatusCn", this.serviceRecord.getServiceStatus().name);

        vo.serviceRecord = jsonObject;

        return vo;
    }
}
